# Gilardi, Fabrizio, "The Temporary Importance of Role Models for Women's Political Representation", American Journal of Political Science
# Code to replicate Table SI26 (Replication of Table A7: Poisson and OLS regression coefficients and standard errors, with an alternative operationalization of the connectivity matrix (W) (inverse of travel time by car between all pairs of municipalities))
# gilardi@ipz.uzh.ch, 2014-06-24

# Set working directory
setwd("../Data/")

# Load packages
library(texreg)

# Load data
d <- read.csv("dataset-full.csv")

# Compute new variables
d$at.least.one.woman.cand.previously.elected <- d$n.women.cand.previously.elected
d$at.least.one.woman.cand.previously.elected[d$n.women.cand.previously.elected > 0] <- 1


###################
# Estimate models #########################################
###################

out.5w <- glm(n.women.elected ~ sl.autod.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand + n.people.elected + referenda + wom.kr + log.dist.zh + log.pop +  kr.svp + steuerfuss + as.factor(stadt.land) + sl.autod.n.women.elected*as.factor(year), data=d, family="poisson")
summary(out.5w)

out.6w <- glm(n.women.elected ~ sl.autod.n.women.elected + at.least.one.woman.elected.lagged + at.least.one.woman.cand.previously.elected + n.men.cand.previously.elected + at.least.one.woman.cand + n.people.elected + referenda + wom.kr + log.dist.zh + log.pop +  kr.svp + steuerfuss + as.factor(stadt.land) + sl.autod.n.women.elected*as.factor(year), data=d, family="poisson")
summary(out.6w)

out.7w <- lm(ratio.votes.w.m ~ sl.autod.n.women.elected + n.women.elected.lagged + n.women.cand.previously.elected + n.men.cand.previously.elected + n.women.cand + n.people.elected + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + sl.autod.n.women.elected*as.factor(year), data=d)
summary(out.7w)

out.8w <- lm(ratio.votes.w.m ~ sl.autod.n.women.elected + at.least.one.woman.elected.lagged + at.least.one.woman.cand.previously.elected + n.men.cand.previously.elected + n.women.cand + n.people.elected + referenda + wom.kr + log.dist.zh + log.pop + kr.svp + steuerfuss + as.factor(stadt.land) + sl.autod.n.women.elected*as.factor(year), data=d)
summary(out.8w)



##############
# Make table ########################################
##############

var.names <- c(
	"(Intercept)",
	"Spatial lag",
	"Nr. xfemale elected ($t-1$)",
	"Nr. xfemale incumbent cand. ($t-1$)",
	"Nr. xmale incumbent cand. ($t-1$)",
	"Nr. xfemale cand.",
	"Nr. seats",
	"Referenda on gender equality",
	"Support for xfemale in cantonal elec.",
	"Distance from Zurich (log)",
	"Population (log)",
	"Support for conservative party",
	"Tax level",
	"Suburb",
	"Countryside",
	seq(1978, 2010, 4),
	"Spatial lag $xx$ 1978",
	"Spatial lag $xx$ 1982",
	"Spatial lag $xx$ 1986",
	"Spatial lag $xx$ 1990",
	"Spatial lag $xx$ 1994",
	"Spatial lag $xx$ 1998",
	"Spatial lag $xx$ 2002",
	"Spatial lag $xx$ 2006",
	"Spatial lag $xx$ 2010",
	"Nr. xfemale elected ($t-1$) $>0$",
	"Nr. xfemale incumbent cand. ($t-1$) $>0$",
	"Nr. xfemale cand. $>0$"
)

model.names <- c("(5)", "(6)", "(7)", "(8)")

texreg(list(out.5w, out.6w, out.7w, out.8w), single.row=T, center=T, dcolumn=T, custom.model.names=model.names, custom.coef.names=var.names)






